﻿<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:variable name="nrOfActors">14</xsl:variable>

  <xsl:output method="html"/>

  <xsl:include href="shared_templates.xsl"/>

  <!-- the main template -->
  <xsl:template match="/">
    <HTML>
      <HEAD>
        <LINK REL="StyleSheet" TYPE="text/css" HREF="exportdetails_item_aqua2.css"></LINK>
        <META http-equiv="Content-Type" content="text/html; charset=UTF-8; toolbar=no"/>
        <TITLE>
          <xsl:value-of select="movieInfo//title"/>
        </TITLE>
      </HEAD>
      <BODY marginheight="0" marginwidth="0" leftmargin="5" rightmargin="5" topmargin="3" bottommargin="5" border="0" class="bodybg" >
        <xsl:apply-templates select="movieInfo/navigation"/>
        <xsl:apply-templates select="movieInfo"/>
        <xsl:apply-templates select="movieInfo/navigation"/>
      </BODY>
    </HTML>
  </xsl:template>

  <xsl:template match="movieInfo">
    <table border="0" cellspacing="0" cellpadding="0" width="100%" class="maintable">
      <tr>
        <td>
          <table border="0" cellspacing="1" cellpadding="0" width="100%">
            <tr>
              <td class="maintitle" width="100%">
                <xsl:value-of select="title"/>
                <xsl:if test="year!=''">
                  <xsl:text> (</xsl:text><xsl:value-of select="year"/>)
                </xsl:if>
              </td>
              <xsl:if test="mpaaRating!=''">
                <td align="right" class="maintitle" valign="centre">
                  <xsl:choose>
                    <xsl:when test="starts-with(mpaaRating, 'G')">
                      <img src="../images/MPAA/G.gif" width="30" height="24"/>
                    </xsl:when>
                    <xsl:when test="starts-with(mpaaRating, 'PG-13')">
                      <img src="../images/MPAA/PG-13.gif" width="59" height="24"/>
                    </xsl:when>
                    <xsl:when test="contains(mpaaRating, 'PG')">
                      <img src="../images/MPAA/PG.gif" width="40" height="24"/>
                    </xsl:when>
                    <xsl:when test="contains(mpaaRating, 'R')">
                      <img src="../images/MPAA/R.gif" width="26" height="24"/>
                    </xsl:when>
                    <xsl:when test="contains(mpaaRating, 'NC-17')">
                      <img src="../images/MPAA/NC-17.gif" width="53" height="24"/>
                    </xsl:when>
                  </xsl:choose>
                </td>
              </xsl:if>
            </tr>
          </table>

          <xsl:if test="tagline!=''">
            <table border="0" cellspacing="1" cellpadding="0" width="100%">
              <tr>
                <td class="tagtitle" width="100%">
                  <xsl:value-of select="tagline"/>
                </td>
              </tr>
            </table>
          </xsl:if>

          <!-- IMDB Rating -->
          <table border="0" cellspacing="1" cellpadding="0" width="100%">
            <xsl:if test="imdbRating!=''">
              <tr valign="center">
                <td class="cellalt1" nowrap="1" width="3%">
                  <xsl:value-of select="/movieInfo/metadata/field[@name='imdbRating']/@label"/>
                </td>
                <td class="stars" width="5%" nowrap="1">
                  <xsl:choose>
                    <xsl:when test="contains(imdbRating,' ')">
                      <xsl:call-template name="starIMDB">
                        <xsl:with-param name="numIMDB" select="substring-before(imdbRating,' ')"/>
                        <xsl:with-param name="imageRoot" select="'../'"/>
                      </xsl:call-template>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:call-template name="starIMDB">
                        <xsl:with-param name="numIMDB" select="imdbRating"/>
                        <xsl:with-param name="imageRoot" select="'../'"/>
                      </xsl:call-template>
                    </xsl:otherwise>
                  </xsl:choose>
                </td>
                <td class="cellalt1" width="25%">
                  <xsl:value-of select="imdbRating"/>
                </td>
              </tr>
            </xsl:if>
          </table>

          <table border="0" cellspacing="1" cellpadding="0" width="100%">
            <tr>
              <xsl:if test="picture!=''">
                <td class="subtitle" height="17">
                  <xsl:value-of select="/movieInfo/metadata/field[@name='picture']/@label"/>
                </td>
              </xsl:if>
              <td class="subtitle" height="17" align="left">
                <xsl:value-of select="/movieInfo/metadata/field[@name='actors']/@label"/>
              </td>
            </tr>
            <tr valign="top">
              <xsl:if test="picture!=''">
                <td width="1" class="detailsbg">
                  <a href="../images/{id}.jpg" target="_blank">
                    <img src="../images/{id}.jpg" border="0" width="175"/>
                  </a>
                </td>
              </xsl:if>
              <td class="detailsbg" valign="top" width="100%">
                <xsl:if test="actors!=''">
                  <table border="0" cellspacing="0" cellpadding="0" width="100%">
                    <tr valign="top">
                      <td>
                        <table border="0" cellspacing="1" cellpadding="0" width="100%">
                          <xsl:for-each select="actors/actor[position() &lt;= $nrOfActors]">
                            <tr>
                              <td class="cellvalue" width="10%" nowrap="1">
                                <xsl:value-of select="node()" />
                              </td>
                            </tr>
                          </xsl:for-each>
                        </table>
                      </td>
                    </tr>
                  </table>
                </xsl:if>
              </td>
            </tr>
          </table>

          <xsl:if test="description!=''">
            <table border="0" cellspacing="1" cellpadding="0" width="100%">
              <tr>
                <td class="subtitle" height="17" align="left">
                  <xsl:value-of select="/movieInfo/metadata/field[@name='description']/@label"/>
                </td>
              </tr>
              <tr>
                <td class="plot" colspan="2">
                  <xsl:call-template name="break">
                    <xsl:with-param name="text" select="description"/>
                  </xsl:call-template>
                </td>
              </tr>
            </table>
          </xsl:if>

          <table border="0" cellspacing="1" cellpadding="0" width="100%">
            <tr>
              <td class="subtitle" height="17" align="left">
                <xsl:value-of select="/movieInfo/metadata/field[@name='movieInfo']/@label"/>
              </td>
            </tr>
            <tr>
              <td valign="top" width="50%" class="detailsbg">

                <table border="0" cellspacing="1" cellpadding="0" width="100%">
                  <xsl:if test="genres!=''">
                    <tr valign="top">
                      <td width="10%" nowrap="1" class="celllabel">
                        <xsl:value-of select="/movieInfo/metadata/field[@name='genres']/@label"/>
                      </td>
                      <td class="cellvalue">
                        <xsl:for-each select="genres/genre">
                          <xsl:value-of select="node()" />
                          <xsl:if test="position()!=last()">
                            <xsl:text>; </xsl:text>
                          </xsl:if>
                        </xsl:for-each>
                      </td>
                    </tr>
                  </xsl:if>
                  <xsl:if test="director!=''">
                    <tr valign="top">
                      <td width="10%" nowrap="1" class="celllabel">
                        <xsl:value-of select="/movieInfo/metadata/field[@name='director']/@label"/>
                      </td>
                      <td class="cellvalue">
                        <xsl:value-of select="director"/>
                      </td>
                    </tr>
                  </xsl:if>
                  <xsl:if test="writer!=''">
                    <tr valign="top">
                      <td width="10%" nowrap="1" class="celllabel">
                        <xsl:value-of select="/movieInfo/metadata/field[@name='writer']/@label"/>
                      </td>
                      <td class="cellvalue">
                        <xsl:apply-templates select="writer"/>
                      </td>
                    </tr>
                  </xsl:if>
                  <xsl:if test="mpaaRating!=''">
                    <tr valign="top">
                      <td class="celllabel" width="10%" nowrap="1">
                        <xsl:value-of select="/movieInfo/metadata/field[@name='mpaaRating']/@label"/>
                      </td>
                      <td class="cellvalue">
                        <xsl:value-of select="mpaaRating"/>
                      </td>
                    </tr>
                  </xsl:if>
                  <xsl:if test="runtime!=''">
                    <tr valign="top">
                      <td class="celllabel" width="10%" nowrap="1">
                        <xsl:value-of select="/movieInfo/metadata/field[@name='runtime']/@label"/>
                      </td>
                      <td class="cellvalue">
                        <xsl:value-of select="runtime"/>
                        <xsl:text> </xsl:text>
                        <xsl:value-of select="/movieInfo/metadata/field[@name='runtimeUnit']/@label"/>
                      </td>
                    </tr>
                  </xsl:if>
                  <xsl:if test="discId!=''">
                    <tr valign="top">
                      <td class="celllabel" width="10%" nowrap="1">
                        <xsl:value-of select="/movieInfo/metadata/field[@name='discId']/@label"/>
                      </td>
                      <td class="cellvalue">
                        <xsl:value-of select="discId"/>
                      </td>
                    </tr>
                  </xsl:if>
                </table>
              </td>
            </tr>
          </table>
        </td>
      </tr>
    </table>

  </xsl:template>

  <xsl:template match="navigation">
    <xsl:choose>
      <xsl:when test="firstlink/@url!=''">
        <td valign="top" class="link">
          <a href="{firstlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movieInfo/metadata/field[@name='first']/@label"/>
            </span>
          </a>|
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td valign="top" class="link">
          <span>
            <xsl:value-of select="/movieInfo/metadata/field[@name='first']/@label"/>
          </span>
        </td>|
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="prevlink/@url!=''">
        <td valign="top" class="link">
          <a href="{prevlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movieInfo/metadata/field[@name='prev']/@label"/>
            </span>
          </a>|
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td valign="top" class="link">
          <span>
            <xsl:value-of select="/movieInfo/metadata/field[@name='prev']/@label"/>
          </span>
        </td>|
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="uplink/@url!=''">
        <td valign="top" class="link">
          <a href="{uplink/@url}" class="link">
            <span>
              <xsl:value-of select="/movieInfo/metadata/field[@name='up']/@label"/>
            </span>
          </a>|
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td valign="top" class="link">
          <span>
            <xsl:value-of select="/movieInfo/metadata/field[@name='up']/@label"/>
          </span>
        </td>|
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="nextlink/@url!=''">
        <td valign="top" class="link">
          <a href="{nextlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movieInfo/metadata/field[@name='next']/@label"/>
            </span>
          </a>|
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td valign="top" class="link">
          <span>
            <xsl:value-of select="/movieInfo/metadata/field[@name='next']/@label"/>
          </span>
        </td>|
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
      <xsl:when test="lastlink/@url!=''">
        <td valign="top" class="value">
          <a href="{lastlink/@url}" class="link">
            <span>
              <xsl:value-of select="/movieInfo/metadata/field[@name='last']/@label"/>
            </span>
          </a>
        </td>
      </xsl:when>
      <xsl:otherwise>
        <td valign="top" class="link">
          <span>
            <xsl:value-of select="/movieInfo/metadata/field[@name='last']/@label"/>
          </span>
        </td>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>